package com.example.reporting.service.Impl;

import com.example.reporting.dao.ReportingMapper;
import com.example.reporting.service.ReportingService;
import com.example.reporting.vo.ReportingVo;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ReportingServiceImpl implements ReportingService {
    @Autowired
    ReportingMapper reportingMapper;
    /**
     * 收费管理-抄表周期全查
     * @param reportingName
     * @return
     */
    @Override
    public CommonResult getReporting(String reportingName) {
        return CommonResult.ok(MyPageHelper.getPageResult(reportingMapper.getReporting(reportingName)));
    }

    /**
     * 收费管理 -抄表周期删除
     * @param id
     * @return
     */
    @Override
    public int delReporting(Integer id) {
        int i =  reportingMapper.delReporting(id);
        return i;
    }

    /**
     * 收费管理-抄表周期增改
     * @param reportingVo
     * @return
     */
    @Override
    public int saveOrUpdateReporting(ReportingVo reportingVo) {
        int i = 0;
        if(reportingVo.getId() == 0){
            reportingVo.setCreateTime(new Date());
            reportingVo.setUpdateTime(new Date());
            reportingVo.setReportingDelFlag(0);
            i = reportingMapper.addReporting(reportingVo);
        }else {
            reportingVo.setUpdateTime(new Date());
            i = reportingMapper.updateReporting(reportingVo);
        }
        return i;
    }
}
